package org.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.entity.CustomerInfo;
import org.example.mapper.CustomerInfoMapper;
import org.example.service.CustomerInfoService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户信息服务实现类
 */
@Service
public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, CustomerInfo> implements CustomerInfoService {
    
    @Override
    public List<CustomerInfo> getByPlName(String plName) {
        QueryWrapper<CustomerInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("pl_name", plName);
        return list(queryWrapper);
    }
    
    @Override
    public List<CustomerInfo> getByPlPhone(String plPhone) {
        QueryWrapper<CustomerInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pl_phone", plPhone);
        return list(queryWrapper);
    }
    
    @Override
    public CustomerInfo getByPlIdNo(String plIdNo) {
        QueryWrapper<CustomerInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pl_id_no", plIdNo);
        return getOne(queryWrapper);
    }
    
    @Override
    public List<CustomerInfo> getByCity(String cityName) {
        QueryWrapper<CustomerInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("sale_city_name", cityName);
        return list(queryWrapper);
    }
    
    @Override
    public List<CustomerInfo> getByAgeRange(Integer minAge, Integer maxAge) {
        QueryWrapper<CustomerInfo> queryWrapper = new QueryWrapper<>();
        if (minAge != null) {
            queryWrapper.ge("age", minAge);
        }
        if (maxAge != null) {
            queryWrapper.le("age", maxAge);
        }
        return list(queryWrapper);
    }
}
